import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/promise_day_record_detail_entity.dart';
import 'package:get/get.dart';

///每日承诺审签
class DailyCommitmentDetailApproveController extends GetxController {
  ///获取相应数据
  PromiseDayRecordDetailEntity? data = Get.arguments as PromiseDayRecordDetailEntity;

  String approvalOpinions = '';
  String approvalUser = '';

  /// 输入回调
  void onOpinion(String value) {
    approvalOpinions = value;
  }

  /// 签字回调
  void onSign(String url) {
    approvalUser = url;
  }

  /// 操作回调
  /// [type]1:通过
  Future<void> onOperation(int type) async {
    if (approvalOpinions.trim().isEmpty) {
      AppToast.showWarning('请输入审批内容');
      return;
    }
    // 默认接口就是通过
    finishPromise();
  }

  ///完成承诺
  finishPromise() async {
    final res = await HttpUtil().generatePostRequest<PromiseDayRecordDetailEntity>(Interface.finishPromise, data: {
      'id': data?.id,
      'promiseContent': approvalOpinions,
    }).execute();
    res.onSuccess((result) {
      Get.back(closeOverlays: true);
    });
  }
}
